package courseInfo;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/*
输入文件为学生成绩信息，包含了必修课与选修课成绩，
格式如下:
班级1，姓名1，科目1，必修，成绩1
班级2，姓名2，科目1，必修，成绩2
班级1，姓名1，科目2，选修，成绩3

实现功能：计算每个学生必修课的平均成绩

*/
public class CourseInfo {
    public static void main(String args[]) throws Exception{
        Configuration conf = new Configuration();
        Job  calculateAvgGrade = Job.getInstance(conf);


        //指定job所在的jar包
        calculateAvgGrade.setJarByClass(CourseInfo.class);

        //设置job的逻辑mapper类
        calculateAvgGrade.setMapperClass(CourseInfoMapper.class);
        //设置job的逻辑reducer类
        calculateAvgGrade.setReducerClass(CourseInfoReducer.class);

        //设置map阶段的输出K-V数据类型
        calculateAvgGrade.setMapOutputKeyClass(Text.class);
        calculateAvgGrade.setMapOutputValueClass(DoubleWritable.class);

        //设置最终输出的K-V数据类型
        calculateAvgGrade.setOutputKeyClass(Text.class);
        calculateAvgGrade.setOutputValueClass(DoubleWritable.class);

        //设置要处理的文本数据所存放的路径
        FileInputFormat.setInputPaths(calculateAvgGrade, new Path("hdfs://127.0.0.1:9000/avgGrade/input"));
        FileOutputFormat.setOutputPath(calculateAvgGrade, new Path("hdfs://127.0.0.1:9000/avgGrade/output"));

        //提交job给集群
        calculateAvgGrade.waitForCompletion(true);
    }


}
